﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations;

namespace Project_1.Models
{
    public class Answer
    {
        public int Id { get; set; }
        public string Content { get; set; }
        public int QuestionId { get; set; }
        public string Username { get; set; }
        public DateTime CreateTime { get; set; }
        public int Likes { get; set; }
        public string LikedUsers { get; set; }
        public int Dislikes { get; set; }
        public string DislikedUsers { get; set; }
    }

    public class AnswerConfiguration : EntityTypeConfiguration<Answer>
    {
        public AnswerConfiguration() : base()
        {
            HasKey(p => p.Id);
            Property(p => p.Id).
                HasColumnName("Id").
                HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).
                IsRequired();
            Property(p => p.Content).
                HasColumnName("Content").
                IsRequired();
            Property(p => p.QuestionId).
                HasColumnName("QuestionId").
                IsRequired();
            Property(p => p.Username).
                HasColumnName("Username").
                IsRequired();
            Property(p => p.Likes).
                HasColumnName("Likes").
                IsRequired();
            Property(p => p.LikedUsers).
                HasColumnName("LikedUsers");
            Property(p => p.Dislikes).
                HasColumnName("Dislikes").
                IsRequired();
            Property(p => p.DislikedUsers).
                HasColumnName("DislikedUsers");
            ToTable("Answers");
        }
    }

    public class CreateAnswerModel
    {
        [Required(ErrorMessage = "You have to input your answer!")]
        public string Content { get; set; }
    }
}